<template>
	<view class="" style="width: 750upx;height: 100vh;background-color: rgb(241, 241, 241)">
		<view class="" style="width: 100upx;height: 10upx;">
			
		</view>
		<view class="" style="background-color: white;width: 650upx;margin: 30upx;border-radius: 10upx;padding: 40upx 20upx;">
			<form action="" @submit="formSubmit" @reset="formReset">
				<view class="" style="display: flex;align-items: center;justify-content: space-between;">
					<view class="">
						地址信息
					</view>
					<view class="" style="display: flex;align-items: center;">
							<radio @click="xuanzhongMR" :checked="checked" name="radio" color="rgb(25,137,250)" value="" /><text>默认收获地址</text>
						
					</view>
				</view>
				<view class="" style="display: flex;align-items: center;justify-content: space-between;margin-top: 30upx;">
					<view class="">
						收件人 <text style="color: red;">*</text>
					</view>
					<view class="Huitext">
						<input :value="nickName" name="shoujianren" placeholder="请填写收件人名字"/>
					</view>
				</view>
				<view class="" style="display: flex;align-items: center;justify-content: space-between;margin-top: 30upx;">
					<view class="">
						手机号 <text style="color: red;">*</text>
					</view>
					<view class="Huitext">
						<input :value="phone" name="phone" placeholder="请填写收件人手机号"/>
					</view>
				</view>
				
				<view class="" style="display: flex;align-items: center;justify-content: space-between;margin-top: 30upx;">
					<view class="">
						所在地区 <text style="color: red;">*</text>
					</view>
					<picker mode="region" :value="date" :start="startDate" :end="endDate" @change="bindDateChange">
						<view class="Huitext" style="justify-content: space-between;">
							
							<view v-if="!ssqQu" class="" style="color: grey;">省、市、区、街道</view>
							<view v-else class="">
								{{ssqSheng}} {{ssqShi}} {{ssqQu}}
			
							</view>
							<uni-icons type="down" color="grey" size="26"></uni-icons>
						</view>
						
					</picker>
				</view>
				
				
				<view class="" style="display: flex;align-items: flex-start;justify-content: space-between;margin-top: 30upx;">
					<view class="">
						详细地址 <text style="color: red;">*</text>
					</view>
					<view class="Huitexts">
						<textarea name="dizhi" :value="detail" placeholder="小区、写字楼、门牌号等"  style="white-space: pre-wrap;overflow-wrap: break-word;height: 180upx;"/>
					</view>
				</view>
				<view class="quedingView">
					
					<button class="btnView" form-type="submit">
						保存
					</button>
				</view>
			</form>
		</view>
		<view class="" style="margin-top: 140upx;">
			
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				addressId:"",
				ssqSheng:"",
				ssqShi:"",
				ssqQu:"",
				checked:false,//默认地址判断、然并卵
				
				nickName:"",
				phone:"",
				detail:"",
				
				
			}
		},
		onLoad(options) {
			if(options.addressId){
				var data=JSON.parse(options.data)
				this.addressId=data.addressId
				this.ssqSheng=data.province
				this.ssqShi=data.city
				this.ssqQu=data.area
				this.detail=data.detail
				this.nickName=data.nickName
				this.phone=data.phone
				this.checked=data.is_default?true:false
			}
		},
			
		methods:{
			baocunBut(){},
			bindDateChange(e){
				this.ssqSheng=e.detail.value[0]
				this.ssqShi=e.detail.value[1]
				this.ssqQu=e.detail.value[2]
				console.log(this.ssq)
			},
			xuanzhongMR(){
				this.checked=!this.checked
			},
			formSubmit: function(e) {
				console.log(e.detail.value)
				this.nickName=e.detail.value.shoujianren
				this.phone=e.detail.value.phone
				this.detail=e.detail.value.dizhi
				
				var  reg_tel = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
				
				if(!this.nickName){
					uni.showToast({
						title: '请填写收件人信息',
						icon:"none",
						duration: 1000
					});
				}else if(!this.phone){
					uni.showToast({
						title: '请填写收件人手机号',
						icon:"none",
						duration: 1000
					});
				}else if(!reg_tel.test(this.phone)){
					uni.showToast({
						title: '手机号格式错误',
						icon:"none",
						duration: 1000
					});
				}else if(!this.detail){
					uni.showToast({
						title: '请填写地址',
						icon:"none",
						duration: 1000
					});
				}else if(!this.ssqQu){
					uni.showToast({
						title: '请选择省市区',
						icon:"none",
						duration: 1000
					});
				}else{
					this.addressAddOrUpdateFC()
				}
				// 
			},
			addressAddOrUpdateFC: async function(){
				const addressAddOrUpdate = await this.$ajax.addressAddOrUpdate({
					addressId: this.addressId,
					area: this.ssqQu,
					city: this.ssqShi,
					detail: this.detail,
					is_default: this.checked?'1':'0',
					nickName: this.nickName,
					phone: this.phone,
					province: this.ssqSheng
				})
				if(addressAddOrUpdate.data.code==200){
					uni.navigateBack({
						delta:1
					})
				}
				console.log(addressAddOrUpdate)
			}
			
		}
	}
</script>

<style>
	.quedingView{
		position: fixed;
		width: 630upx;
		bottom:0upx;
		height: 100upx;
		background-color: white;
		padding: 0 60upx;
		display: flex;
		align-items: center;
		/* justify-content: space-between; */
		justify-content: center;
		margin-left: -50upx;
	}
	.btnView{
		padding: 6.5px 0 6.5px;
		background-image: linear-gradient(-34deg, #106bf3 0%, #00c0fa 100%);
		box-shadow: 1.5px 2px 15.5px #0d70f31a;
		border-radius: 5px;
		width: 99.5px;
		height: 23.5px;
		color: white;
		display: flex;
		align-items: center;
		justify-content: center;
		font-weight: bold;
	}
	.Huitext{
		background-color: rgb(249,249,249);
		border-radius: 40upx;
		min-height: 80upx;
		width: 400upx;
		padding-left: 50upx;
		display: flex;
		align-items: center;
	}
	
	.Huitexts{
		background-color: rgb(249,249,249);
		border-radius: 40upx;
		height: 200upx;
		width: 370upx;
		padding-left: 50upx;
		display: flex;
		align-items: flex-start;
		padding-top: 20upx;
		padding-right: 30upx;
	}
</style>